﻿namespace Pub.Class
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text;

    public class Rand
    {
        public static string RandColor()
        {
            string str = Convert.ToString(RndInt(0, 0xff), 0x10);
            str = (str.Length == 1) ? ("0" + str) : str;
            string str2 = Convert.ToString(RndInt(0, 0xff), 0x10);
            str2 = (str2.Length == 1) ? ("0" + str2) : str2;
            string str3 = Convert.ToString(RndInt(0, 0xff), 0x10);
            str3 = (str3.Length == 1) ? ("0" + str3) : str3;
            return (str + str2 + str3);
        }

        public static IList<string> RandColor(int len)
        {
            IList<string> list = new List<string>();
            for (int i = 0; i < len; i++)
            {
                list.Add(RandColor());
            }
            return list;
        }

        public static string RndCode(int len)
        {
            char[] chArray = new char[] { 
                'a', 'b', 'd', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 
                'q', 's', 't', 'u', 'v', 'w', 'z', 'y', 'x', '0', '1', '2', '3', '4', '5', '6', 
                '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 
                'N', 'Q', 'P', 'R', 'T', 'S', 'V', 'U', 'W', 'X', 'Y', 'Z'
             };
            StringBuilder builder = new StringBuilder();
            Random random = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < len; i++)
            {
                builder.Append(chArray[random.Next(0, chArray.Length)].ToString());
            }
            return builder.ToString();
        }

        public static IList<string> RndCodeList(int len, int count)
        {
            IList<string> list = new List<string>();
            for (int i = 0; i < count; i++)
            {
                list.Add(RndCode(len));
            }
            return list;
        }

        public static Color RndColor(bool iUseAlpha)
        {
            int alpha = 0xff;
            if (!iUseAlpha)
            {
                alpha = RndInt(0, 0xff);
            }
            int red = RndInt(0, 0xff);
            int blue = RndInt(0, 0xff);
            int green = RndInt(0, 0xff);
            return Color.FromArgb(alpha, red, green, blue);
        }

        public static string RndDateStr()
        {
            return (DateTime.Now.ToString("yyyyMMddHHmmssfff") + RndInt(0x3e8, 0x270f).ToString());
        }

        public static IList<string> RndDateStr(int len)
        {
            IList<string> list = new List<string>();
            for (int i = 0; i < len; i++)
            {
                list.Add(RndDateStr());
            }
            return list;
        }

        public static string RndGuid()
        {
            return Guid.NewGuid().ToString();
        }

        public static IList<string> RndGuid(int len)
        {
            IList<string> list = new List<string>();
            for (int i = 0; i < len; i++)
            {
                list.Add(RndGuid());
            }
            return list;
        }

        public static IList<int> RndInt(int len)
        {
            return RndInt(0, 0x7fffffff, len);
        }

        public static int RndInt(int num1, int num2)
        {
            Random random = new Random(Guid.NewGuid().GetHashCode());
            return random.Next(num1, num2);
        }

        public static IList<int> RndInt(int num1, int num2, int len)
        {
            IList<int> list = new List<int>();
            for (int i = 0; i < len; i++)
            {
                list.Add(RndInt(num1, num2));
            }
            return list;
        }

        public static string RndLetter(int len)
        {
            char[] chArray = new char[] { 
                'a', 'b', 'd', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 
                'q', 's', 't', 'u', 'v', 'w', 'z', 'y', 'x', '_', 'A', 'B', 'C', 'D', 'E', 'F', 
                'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'Q', 'P', 'R', 'T', 'S', 'V', 'U', 'W', 
                'X', 'Y', 'Z'
             };
            StringBuilder builder = new StringBuilder();
            Random random = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < len; i++)
            {
                builder.Append(chArray[random.Next(0, chArray.Length)].ToString());
            }
            return builder.ToString();
        }

        public static IList<string> RndLetterList(int len, int count)
        {
            IList<string> list = new List<string>();
            for (int i = 0; i < count; i++)
            {
                list.Add(RndLetter(len));
            }
            return list;
        }

        public static string RndNum(int len)
        {
            char[] chArray = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            StringBuilder builder = new StringBuilder();
            Random random = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < len; i++)
            {
                builder.Append(chArray[random.Next(0, 9)].ToString());
            }
            return builder.ToString();
        }

        public static IList<string> RndNum(int len, int count)
        {
            IList<string> list = new List<string>();
            for (int i = 0; i < count; i++)
            {
                list.Add(RndNum(len));
            }
            return list;
        }
    }
}

